package Gather.StreamExercise.StreamDome002;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName:StreamExercise001
 * Package:Gather.StreamExercise.StreamDome002
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/2/24-22:36
 * @Version:v1.0
 */
public class StreamExercise001 {
    /*定义一个集合,并添加一些整数1,2,3,4,5,6,7,8,9,10
     * 过滤奇数,只留下偶数
     * 并将结果保存起来*/
    public static void main(String[] args) {
        ArrayList<Integer> list1 = new ArrayList<>();
//        ArrayList<Integer> list2 = new ArrayList<>();
        Collections.addAll(list1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        System.out.println(list1);
//        list1.stream().filter(s -> s % 2 == 0).filter(s -> list2.add(s)).forEach(s-> System.out.println(s));

        //过滤奇数,只留下偶数
        //进行判断,如果是偶数返回true
        List<Integer> list2 = list1.stream()
                .filter(s -> s % 2 == 0).collect(Collectors.toList());
        System.out.println(list2);


    }
}
